package com.liuh.ssh2.action;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.liuh.ssh2.pojo.User;
import com.liuh.ssh2.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

public class IndexAction extends ActionSupport{
	
	User u;
	UserService userService;
	String userJson;
	
	public String getUserJson() {
		return userJson;
	}

	public void setUserJson(String userJson) {
		this.userJson = userJson;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public User getU() {
		return u;
	}

	public void setU(User u) {
		this.u = u;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		userService.addUser(u);
		return "success";
	}
	
	public String execute2() throws Exception {
		// TODO Auto-generated method stub
		User u=userService.getUserById(77);
		u.setEmail("nidaye");
		userService.updUser(u);
		return "success";
	}
	
	/**
	 * @note 分页
	 * @author liuh
	 * */
	public String userJson() {
		List<User> users=userService.getUserPage(2, 6);
		userJson=JSON.toJSONString(users);
		return "success";
	}

}
